#include "fig_flyingpath.h"
#include "fighter.h"

#include "num/crc32.h"

FIGFlyingPath::FIGFlyingPath()
{
	m_TempVec2 = math::Vec2(0,0);
	m_PathInfo.Rotation = 0;

	m_FlyingPaths[PATH_NONE] = NULL;

	FIGFlyingPath::FlyingPath* pPath = new FIGFlyingPath::FlyingPath();
	Path_Side_Rotate_Left(pPath);
	
	
	pPath = new FIGFlyingPath::FlyingPath();
	Path_Side_Rotate_Right(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_TontCout(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_DragonTontCount(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_DragonLeftToRight(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_DragonRightToLeft(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_LeftConer_To_RightConer1(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_RightConer_To_LeftConer1(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_LeftConer_To_RightConer2(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_RightConer_To_LeftConer2(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_ComeRight_Circle(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_ComeLeft_Circle(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_Left_To_Right_Diagonal(pPath);

	pPath = new FIGFlyingPath::FlyingPath();
	Path_Right_To_Left_Diagonal(pPath);
	 

}

void	FIGFlyingPath::Path_TontCout(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.5f , 0.5f);
	math::Vec2 Dir = math::Vec2(0.0f, -1.0f);
	pPath->m_StartPos = StartPos + ( Dir * 0.55f) ;
	pPath->m_InitialRotation = 0.0f;

	pPath->AddPathPiece(0,0,0.1f);
	pPath->AddPathPiece(20,30,0);
	pPath->AddPathPiece(-40,30,0);
	pPath->AddPathPiece(40,30,0);
	pPath->AddPathPiece(-40,30,0);
	pPath->AddPathPiece(40,30,0);
	pPath->AddPathPiece(-40,30,0);
	pPath->AddPathPiece(40,30,0);
	pPath->AddPathPiece(-40,30,0);
	m_FlyingPaths[FIGFlyingPath::PATH_TOUNT_COUT] = pPath;
}

void	FIGFlyingPath::Path_DragonTontCount(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.5f , 0.5f);
	math::Vec2 Dir = math::Vec2(0.0f, -1.0f);
	pPath->m_StartPos = StartPos + ( Dir * 0.6f) ;
	pPath->m_InitialRotation = 0.0f;

	pPath->AddPathPiece(25,30,0);

	for(int i = 0; i < 14; i++)
	{
		pPath->AddPathPiece(-50,30,0);
		pPath->AddPathPiece(50,30,0);
	}
	

	m_FlyingPaths[FIGFlyingPath::PATH_DRAGON_TONT_COUNT] = pPath;
}

void	FIGFlyingPath::Path_DragonLeftToRight(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.5f , 0.5f);
	math::Vec2 Dir = math::Vec2(-1.0f, -1.0f);

	pPath->m_StartPos = StartPos + ( Dir * 0.6f) ;
	pPath->m_InitialRotation = 45.0f;
	
    pPath->AddPathPiece(0,0,0.7f);
	pPath->AddPathPiece(360,40,0);
	pPath->AddPathPiece(90,40,0);
	pPath->AddPathPiece(0,0,1.75f);		

	m_FlyingPaths[FIGFlyingPath::PATH_DRAGON_LEFT_TO_RIGHT] = pPath;
}

void	FIGFlyingPath::Path_DragonRightToLeft(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.5f , 0.5f);
	math::Vec2 Dir = math::Vec2(1.0f, -1.0f);

	pPath->m_StartPos = StartPos + ( Dir * 0.6f) ;
	pPath->m_InitialRotation = -45.0f;
	
    pPath->AddPathPiece(0,0,0.7f);
	pPath->AddPathPiece(-360,40,0);
	pPath->AddPathPiece(-90,40,0);
	pPath->AddPathPiece(0,0,1.75f);			
	

	m_FlyingPaths[FIGFlyingPath::PATH_DRAGON_RIGHT_TO_LEFT] = pPath;
}

void		FIGFlyingPath::Path_Side_Rotate_Left(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.5f , 0.5f);
	math::Vec2 Dir = math::Vec2(-1.0f, -1.0f);

	pPath->m_StartPos = StartPos + ( Dir * 0.55f) ;
	pPath->m_InitialRotation = 45.0f;
	

	pPath->AddPathPiece( 0,0,0.3f);
	pPath->AddPathPiece(-360,55,0);
	pPath->AddPathPiece( 0,0,0.4f);
	pPath->AddPathPiece( 80,35,0);
	pPath->AddPathPiece( 0,0,1.0f);
	m_FlyingPaths[FIGFlyingPath::PATH_SIDE_ROTATE_LEFT] = pPath;
	
}

void		FIGFlyingPath::Path_Side_Rotate_Right(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.5f , 0.5f);
	math::Vec2 Dir = math::Vec2(1.0f, -1.0f);

	pPath->m_StartPos = StartPos + ( Dir * 0.55f) ;
	pPath->m_InitialRotation =  -45.0f;
	

	pPath->AddPathPiece( 0,0,0.5f);
	pPath->AddPathPiece(360,55,0);
	pPath->AddPathPiece( 0,0,0.4f);
	pPath->AddPathPiece( -80,35,0);
	pPath->AddPathPiece( 0,0,1.0f);
	m_FlyingPaths[FIGFlyingPath::PATH_SIDE_ROTATE_RIGHT] = pPath;

}

void		FIGFlyingPath::Path_LeftConer_To_RightConer1(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.48f , 0.52f);
	math::Vec2 Dir = math::Vec2(-1.0f, -1.0f);

	pPath->m_StartPos = StartPos + ( Dir * 0.585f) ;
	pPath->m_InitialRotation = 45.0f;
	
    pPath->AddPathPiece(0,0,0.5f);
	pPath->AddPathPiece(90,55,0);
	pPath->AddPathPiece(0,0,0.5f);
	m_FlyingPaths[FIGFlyingPath::PATH_LEFTCONER_TO_RIGHT_CONER1] = pPath;	

} 

void		FIGFlyingPath::Path_LeftConer_To_RightConer2(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.52f , 0.48f);
	math::Vec2 Dir = math::Vec2(-1.0f, -1.0f);

	pPath->m_StartPos = StartPos + ( Dir * 0.55f) ;
	pPath->m_InitialRotation = 45.0f;
	
    pPath->AddPathPiece(0,0,0.5f);
	pPath->AddPathPiece(90,55,0);
	pPath->AddPathPiece(0,0,0.5f);
	m_FlyingPaths[FIGFlyingPath::PATH_LEFTCONER_TO_RIGHT_CONER2] = pPath;	

}
void		FIGFlyingPath::Path_RightConer_To_LeftConer1(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.40f , 0.52f);
	math::Vec2 Dir = math::Vec2(1.0f, -1.0f);

	pPath->m_StartPos = StartPos + ( Dir * 0.585f) ;
	pPath->m_InitialRotation = -45.0f;
	
	pPath->AddPathPiece(0,0,0.5f);
	pPath->AddPathPiece(-90,55,0);
	pPath->AddPathPiece(0,0,0.5f);
	m_FlyingPaths[FIGFlyingPath::PATH_RIGHTCONER_TO_LEFT_CONER1] = pPath;	

}

void		FIGFlyingPath::Path_RightConer_To_LeftConer2(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.52f , 0.48f);
	math::Vec2 Dir = math::Vec2(1.0f, -1.0f);

	pPath->m_StartPos = StartPos + ( Dir * 0.55f) ;
	pPath->m_InitialRotation = -45.0f;
	
	pPath->AddPathPiece(0,0,0.5f);
	pPath->AddPathPiece(-90,55,0);
	pPath->AddPathPiece(0,0,0.5f);
	m_FlyingPaths[FIGFlyingPath::PATH_RIGHTCONER_TO_LEFT_CONER2] = pPath;	

}

void		FIGFlyingPath::Path_ComeRight_Circle(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.8f , -0.1f);
	
	pPath->m_StartPos = StartPos;
	pPath->m_InitialRotation = 0.0f;

	pPath->AddPathPiece(-10,5,0);

	// one circle each
	pPath->AddPathPiece(-365,45,0);
	pPath->AddPathPiece(-365,45,0);
	pPath->AddPathPiece(-365,45,0);

	pPath->AddPathPiece(-100,45,0);

	pPath->AddPathPiece(0,0,1.0f);

	m_FlyingPaths[FIGFlyingPath::PATH_COMERIGHT_CIRCLE] = pPath;	
}

void		FIGFlyingPath::Path_ComeLeft_Circle(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 0.2f , -0.1f);
	
	pPath->m_StartPos = StartPos;
	pPath->m_InitialRotation = 0.0f;

	pPath->AddPathPiece(10,5,0);

	// one circle each
	pPath->AddPathPiece(365,45,0);
	pPath->AddPathPiece(365,45,0);
	pPath->AddPathPiece(365,45,0);

	pPath->AddPathPiece(100,45,0);

	pPath->AddPathPiece(0,0,1.0f);

	m_FlyingPaths[FIGFlyingPath::PATH_COMELEFT_CIRCLE] = pPath;	
}

void		FIGFlyingPath::Path_Left_To_Right_Diagonal(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( -0.2f , 0.05f);
	
	pPath->m_StartPos = StartPos;
	pPath->m_InitialRotation = 90.0f;

	pPath->AddPathPiece(0,0,4.0f);

	
	m_FlyingPaths[FIGFlyingPath::PATH_LEFT_TO_RIGHT_DIAGONAL] = pPath;	
}

void		FIGFlyingPath::Path_Right_To_Left_Diagonal(FIGFlyingPath::FlyingPath* pPath)
{
	math::Vec2 StartPos = math::Vec2( 1.2f , 0.1f);
	
	pPath->m_StartPos = StartPos;
	pPath->m_InitialRotation = -90.0f;

	pPath->AddPathPiece(0,0,4.0f);

	
	m_FlyingPaths[FIGFlyingPath::PATH_RIGHT_TO_LEFT_DIAGONAL] = pPath;	
}

FIGFlyingPath::PATH_TYPE		FIGFlyingPath::MapNameToType(const std::string& TypeName)
{

	for (unsigned int i = 0; i < PATH_COUNT; i++)
		if (strcmpi( MapTypeToName((PATH_TYPE)i).c_str(), TypeName.c_str() ) == 0)
			return (PATH_TYPE)i;

	return PATH_NONE; 

	
}

std::string		FIGFlyingPath::MapTypeToName(FIGFlyingPath::PATH_TYPE PathType)
{
	switch(PathType)
	{
		case PATH_TOUNT_COUT:
			return "Tont_Cout";

		case PATH_SIDE_ROTATE_LEFT:
			return "Side_Rotate_Left";

		case  PATH_SIDE_ROTATE_RIGHT:
			return "Side_Rotate_Right";

		case  PATH_LEFTCONER_TO_RIGHT_CONER1:
			return "Left_Coner_To_Right_Coner1";

		case  PATH_LEFTCONER_TO_RIGHT_CONER2:
			return "Left_Coner_To_Right_Coner2";

		case PATH_RIGHTCONER_TO_LEFT_CONER1:
			return "Right_Coner_To_Left_Coner2";

		case PATH_RIGHTCONER_TO_LEFT_CONER2:
			return "Right_Coner_To_Left_Coner1";

		case PATH_COMERIGHT_CIRCLE:
			return "ComeRight_Circle";

		case  PATH_COMELEFT_CIRCLE:
			return "ComeLeft_Circle";

		case PATH_DRAGON_TONT_COUNT:
			return "Dragon_Tont_Count";

		case PATH_DRAGON_LEFT_TO_RIGHT:
			return "Dragon_Left_To_Right";

		case PATH_DRAGON_RIGHT_TO_LEFT:
			return "Dragon_Right_To_Left";

		case PATH_LEFT_TO_RIGHT_DIAGONAL:
			return "Left_To_Right_Diagonal";

		case PATH_RIGHT_TO_LEFT_DIAGONAL:
			return "Right_To_Left_Diagonal";

		default:
			break;
	}
	
	return "";

}
